home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / GLOBAL.H < prev    next >
C/C++ Source or Header  |  1990-08-10  |  7KB  |  228 lines

  1. /* Global definitions used by every source file.
  2.  * Some may be compiler dependent.
  3.  */
  4.  
  5. /* Indexes into binmode in files.c; hook for compilers that have special
  6.  * open modes for binary files
  7.  */
  8. #define READ_BINARY    0
  9. #define WRITE_BINARY    1
  10. #define APPEND_BINARY    2
  11. extern char *binmode[];
  12.  
  13. /* These two lines assume that your compiler's longs are 32 bits and
  14.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  15.  * but it doesn't matter if they're signed or unsigned.
  16.  */
  17. typedef long int32;        /* 32-bit signed integer */
  18. typedef unsigned short int16;    /* 16-bit unsigned integer */
  19. #define uchar(x) ((unsigned char)(x))
  20. #define MAXINT16 ((int16)65535) /* Largest 16-bit integer */
  21.  
  22. /* not all compilers support defined(SYM) in the preprocessor.... */
  23. #ifdef NODEFINED
  24. # define defined(x)    (x)
  25. #endif
  26.  
  27. /* Since not all compilers support structure assignment, the ASSIGN()
  28.  * macro is used. This controls how it's actually implemented.
  29.  */
  30. #ifdef NOSTRUCTASSIGN
  31.             /* Version for old compilers that don't support it */
  32. # define ASSIGN(a,b)    memcpy((char *)&(a),(char *)&(b),sizeof(b));
  33. #else
  34.             /* Version for compilers that do */
  35. # define ASSIGN(a,b)    ((a) = (b))
  36. #endif
  37.  
  38. #if (defined(SYS5) || defined(MSC) || defined(__TURBOC__))
  39. # define rindex        strrchr
  40. # define index        strchr
  41. #else
  42. # define strrchr    rindex
  43. # define strchr        index
  44. #endif
  45.  
  46. #if (defined(MSC) || defined(__TURBOC__))
  47. /* Turbo C needs prototypes for library functions. MSC would like them. */
  48. # ifdef ATARI_ST
  49. #  include <tos.h>
  50. # endif
  51. # ifdef MSDOS
  52. #  ifdef MSC
  53. #   include <dos.h>
  54. #  endif
  55. #  ifdef __TURBOC__
  56. #   define interrupt
  57. #   include <dos.h>
  58. #   undef disable
  59. #   define disable Disable
  60. #  endif
  61. # endif
  62. # include <stdio.h>
  63. # include <stdlib.h>
  64. # include <string.h>
  65. # include <time.h>
  66. extern long htol(char *);
  67. # ifdef ATARI_ST
  68. extern log_msg(char *,...);
  69. # endif
  70. #else
  71. /* Heavily used functions from the standard library */
  72. char *index(),*rindex(),*ctime(),*tmpnam(),*fgets();
  73. long atol(),htol();
  74. # if ((defined(ATARI_ST) && defined(MWC)) || defined(UNIX))
  75. char *malloc(),*calloc();
  76. # else
  77. void *malloc(),*calloc();
  78. # endif
  79. #endif
  80.  
  81. /* Define null object pointer in case stdio.h isn't included */
  82. #ifndef NULL
  83. /* General purpose NULL pointer */
  84. # if (defined(ATARI_ST) && defined(MWC))
  85. #  define NULL (char *)0    /* MW does not like funny typecasts on void */
  86. # else
  87. #  define NULL (void *)0
  88. # endif
  89. #endif
  90. #define NULLCHAR (char *)0    /* Null character pointer */
  91. #define NULLFP     (int (*)())0    /* Null pointer to function returning int */
  92. #define NULLVFP     (void (*)())0    /* Null pointer to function returning void */
  93. #define NULLFILE (FILE *)0    /* Null file pointer */
  94.  
  95. #ifndef min
  96. /* General purpose function macros */
  97. # define min(x,y)    ((x)<(y)?(x):(y))    /* Lesser of two args */
  98. # define max(x,y)    ((x)>(y)?(x):(y))    /* Greater of two args */
  99. #endif
  100.  
  101. #if (defined(MPU8086) || defined(MPU8080) || defined(vax) || defined(MSDOS) || defined(M_I86) || defined(M_I286) || defined(M_I386))
  102. # define LITTLE_ENDIAN        /* Low order bytes are first in memory */
  103. #endif                /* Almost all other machines are big-endian */
  104.  
  105. #if (defined(AMIGA) || defined(ATARI_ST) || defined(MAC))
  106. # define I_ALIGN    2    /* word-aligned integer storage */
  107. #else
  108. # define I_ALIGN    1    /* byte-aligned integer storage */
  109. #endif
  110.  
  111. /* Define LARGECODE and LARGEDATA depending on the memory model ('86 only) */
  112. #if (defined(M_I86MM) || defined(__MEDIUM__))
  113. # define LARGECODE
  114. #endif
  115.  
  116. #if (defined(M_I86LM) || defined(M_I86HM) || defined(__LARGE__) || defined(__HUGE__))
  117. # define LARGECODE
  118. # define LARGEDATA
  119. #endif
  120.  
  121. /* In LARGE model, a pointer can't be register so leave them to the compiler */
  122. #ifdef LARGEDATA
  123. # define register
  124. #endif
  125.  
  126. /* Convert an address to a LONG value and vice-versa for printing and input */
  127. /* Of course, the Intel 80x86 line of processors causes a lot of headaches */
  128. #if (defined(MSDOS) || defined(M_I86MM))
  129. # if (defined(LARGEDATA) && defined(__TURBOC__))
  130. #  define ptr2long(x)    (((unsigned long) (x) >> 12) + (unsigned) (x))
  131. #  define long2ptr(x)    ((((x) << 12) & 0xffff0000L) + ((x) & 0x0f))
  132. # endif
  133. # if (!defined(LARGEDATA))
  134.    long    ptr2long();            /* for fuzzy segment addresses */
  135. #  define long2ptr(x)    ((char *) (x))
  136. # endif
  137. #endif
  138.  
  139. #ifndef long2ptr
  140. # define ptr2long(x)    ((long) (x))    /* typecast suffices for others */
  141. # define long2ptr(x)    ((char *) (x))
  142. #endif
  143.  
  144. #ifdef MPU8080 /* Assembler routines are available */
  145. int16 hinibble(),lonibble(),hibyte(),lobyte(),hiword(),loword();
  146. #else
  147. /* Extract a short from a long */
  148. # if (defined(ATARI_ST) && defined(MWC) && (MWC < 306))
  149. extern int Sixteen;            /* MW C before 3.0.6 cannot << 16 */
  150. #  define hiword(x)    ((int16)((x) >> Sixteen)) /* hide compiler bug.. */
  151. # else
  152. #  define hiword(x)    ((int16)((x) >> 16))
  153. # endif
  154. # define loword(x)    ((int16)(x))
  155.  
  156. /* Extract a byte from a short */
  157. # define hibyte(x)    (uchar((x) >> 8))
  158. # define lobyte(x)    (uchar(x))
  159.  
  160. /* Extract nibbles from a byte */
  161. # define hinibble(x)    (((x) >> 4) & 0xf)
  162. # define lonibble(x)    ((x) & 0xf)
  163. #endif
  164.  
  165. #ifdef LITTLE_ENDIAN
  166. int16 get16();
  167. int32 get32();
  168. #else
  169. #define get16(cp)    (*((int16 *)(cp)))
  170. #define get32(cp)    (*((int32 *)(cp)))
  171. #endif
  172.  
  173. #if (defined(LITTLE_ENDIAN) || I_ALIGN > 1)
  174. char *put16(),*put32();
  175. #else
  176. #define put16(cp,x)    (*((int16 *)(cp)) = (x), (cp) + sizeof(int16))
  177. #define put32(cp,x)    (*((int32 *)(cp)) = (x), (cp) + sizeof(int32))
  178. #endif
  179.  
  180. #if defined(ATARI_ST)
  181. /* the 68000 processor won't let you disable interrupts in user mode
  182.  * therefore, a trap handler has been defined to do this, and it's
  183.  * installed as trap #5. The Mark Williams compiler generates a trap #5
  184.  * when you call the magic function "micro_rtx" (their multi-tasking
  185.  * executive).    From version 3, it can generate any trap number using
  186.  * the magic function _VtrapX_().  We'll use trap #7 in that case.
  187.  * Turbo-C will have to call a function calling the trap.
  188.  * the trap handler returns the previous processor level as a char.
  189.  */
  190.  
  191. # ifdef __TURBOC__
  192. extern char spl(char);            /* function doing the TRAP #5 */
  193. #  define disable()    spl(6)
  194. #  define restore(state) spl(state)
  195. # endif
  196.  
  197. # ifdef MWC
  198. #  if MWC < 300
  199. #   define disable()    micro_rtx(6)
  200. #   define restore(st)    micro_rtx(st)
  201. #  else
  202. #   define disable()    _Vtrap7_(6)
  203. #   define restore(st)    _Vtrap7_(st)
  204. #  endif
  205.  
  206. /* a quick, non-checking free() function as a macro (for MW C only) */
  207. #  ifdef QFREE
  208. #   define free(p)    ((char *) (p))[-1] |= 1;
  209. #  endif
  210. #  define NOTMPFILE            /* MW C lacks tmpfile() */
  211. # endif
  212. #endif
  213.  
  214. #ifdef NOTMPFILE
  215. # define fclose(fp)    notmpfclose(fp) /* our own fclose() to delete tmpfiles */
  216. #endif
  217.  
  218. /* Hardware I/O functions that can be replaced with macros in some compilers */
  219. #ifdef MSC
  220. # define inportb    inp
  221. # define outportb    outp
  222. #else
  223. # ifndef __TURBOC__
  224. unsigned char inportb();
  225. unsigned int inportw();
  226. # endif
  227. #endif
  228.